package logic

import (
	"api/pkg"
	"context"
	"order_srv/order"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsReleaseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsReleaseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsReleaseLogic {
	return &GoodsReleaseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsReleaseLogic) GoodsRelease(req *types.GoodsReleaseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	release, err := l.svcCtx.OrderSrv.GoodsRelease(l.ctx, &order.GoodsReleaseRequest{
		UserId:     req.UserId,
		GoodsName:  req.GoodsName,
		GoodsPrice: float32(req.GoodsPrice),
		GoodsStock: req.GoodsStock,
		GoodsCover: req.GoodsCover,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Tri(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "商品发布成功",
		Data: map[string]interface{}{
			"Release": release.GoodsId,
		},
	}, nil
}
